package cn.edu.zju.gis.disasterBE.sever.controller;

import cn.edu.zju.gis.disasterBE.sever.commons.annotation.PassToken;
import cn.edu.zju.gis.disasterBE.sever.commons.annotation.UserLoginToken;
import cn.edu.zju.gis.disasterBE.sever.entity.DisasterResponse;
import cn.edu.zju.gis.disasterBE.sever.entity.User;
import cn.edu.zju.gis.disasterBE.sever.entity.global.MyResponse;
import cn.edu.zju.gis.disasterBE.sever.service.DisasterResponseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("灾害响应")
@RestController
@RequestMapping("/disasterResponse")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class DisasterResponseController {
    private final DisasterResponseService disasterResponseService;

    //获取数据库中所有的灾害数据用于前端显示
    @ApiOperation("获得数据库中所有灾害")
    @GetMapping("/disasterGetAll")
    public MyResponse<List<DisasterResponse>> disasterGetAll()
    {
        return disasterResponseService.disasterGetAll();
    }

    @ApiOperation("存入数据")
    @PostMapping("/saveDisaster")
    public MyResponse<DisasterResponse> saveDisaster(@RequestBody String json)
    {

        return disasterResponseService.saveDisaster(json);
    }

    @ApiOperation("获得数据库中正在响应的灾害灾害")
    @GetMapping("/durableDisasterGet")
    public MyResponse<List<DisasterResponse>> durableDisasterGet()
    {
        return disasterResponseService.durableDisasterGet();
    }

    @ApiOperation("结束灾害响应")
    @GetMapping("/endResponse")
    public MyResponse<String> endResponse(@RequestParam String did)
    {
        System.out.println("end disaster");
        return disasterResponseService.endResponse(did);
    }

}
